package com.mh.study.jackson.annotations;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

import java.util.ArrayList;
import java.util.List;

/**
 * @author meng.han
 * @since 2021-11-26
 */
@JsonIdentityInfo(
        generator = ObjectIdGenerators.PropertyGenerator.class,
        property = "id")
public class UserWithIdentity {

    public int id;
    public String name;
    public List<ItemWithIdentity> userItems;

    public UserWithIdentity() {
    }

    public UserWithIdentity(int id, String name) {
        this.id = id;
        this.name = name;
        this.userItems = new ArrayList<>();
    }

    public void addItem(ItemWithIdentity item) {
        this.userItems.add(item);
    }
}
